package com.tencent.txcc.mq.producer;

import com.tencent.txcc.domain.MediaFile;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class RocketMQProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public boolean producerSendMessage(MediaFile mediaFile){
        Message<MediaFile> message = MessageBuilder.withPayload(mediaFile).build();
        SendResult sendResult = rocketMQTemplate.syncSend("topic-video:tag-push", message);
        SendStatus sendStatus = sendResult.getSendStatus();
        return SendStatus.SEND_OK == sendStatus ? true : false;
    }
}
